﻿using Sport_Orders.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Sport_Orders.Program.Module_Windows
{
    /// <summary>
    /// Логика взаимодействия для Cheque.xaml
    /// </summary>
    public partial class Cheque : Window
    {
        // Полученные товары в виде заказа
        List<Tovar> orderTovars = new List<Tovar>();

        public Cheque(List<Tovar> tovars, Orders order)
        {
            InitializeComponent();
            orderTovars = tovars;

            TxbCheque.Text = $"Заказ №{order.ID_order} от {order.dateOrd.ToShortDateString()}";
            TxbCheque.Text += $"\nПункт выдачи: {order.Station.addressSt}";
            if (orderTovars.Min(ordTov => ordTov.countTovar) > 3)
                TxbCheque.Text += $"\nСрок доставки: 3 дня";
            else TxbCheque.Text += $"\nСрок доставки: 6 дней";
            TxbCheque.Text += $"\n\n- Товары -";

            foreach (var tovar in orderTovars)
                TxbCheque.Text += $"\n{tovar.nameTovar} --- {tovar.price}";

            TxbCheque.Text += $"\nИтоговая цена: {orderTovars.Sum(tovar => tovar.totalPrice)} руб.";
            TxbCheque.Text += $"\nСкидка: {orderTovars.Sum(tovar => tovar.price) - tovars.Sum(tovar => tovar.totalPrice)} руб.";
        }

        // печать чека
        private void BtnPrintCheque_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog spd = new PrintDialog();

            if (spd.ShowDialog() == true)
            {
                IDocumentPaginatorSource ipd = FDcheque;
                spd.PrintDocument(ipd.DocumentPaginator, "FlowDocument");
            }
        }
    }
}
